package org.ftc.dao;

import java.util.List;

import org.ftc.domain.CTMap;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class CTMapDao extends CurrentDao <CTMap, String> {

	@Override
	public CTMap load(String id) {
		return super.load(id);
	}

	@Override
	public CTMap get(String id) {
		return super.get(id);
	}

	@Override
	public synchronized boolean save(CTMap entity) {
		return super.save(entity);
	}

	@Override
	public synchronized boolean saveOrUpdate(CTMap entity) {
		return super.saveOrUpdate(entity);
	}

	@Override
	public synchronized boolean update(CTMap entity) {
		return super.update(entity);
	}

	@Override
	public synchronized boolean delete(CTMap entity) {
		return super.delete(entity);
	}

	@Override
	public synchronized boolean delete(String id) {
		return super.delete(id);
	}
	
	@Override
	public List<CTMap> findPage(int offset, int pageSize) {
		return super.findPage(offset, pageSize);
	}

	@SuppressWarnings("unchecked")
	public List<CTMap> findAll(String tCode) {
		try{	
			Criteria criteria = getSession().createCriteria(CTMap.class); 
			criteria.createAlias("committee", "committee");
			criteria.createAlias("committeeTeam", "committeeTeam");
			criteria.add(Restrictions.eq("committeeTeam.tCode", tCode));
			criteria.addOrder(Order.asc("sort"));
			return (List<CTMap>) criteria.list();
		}catch( Exception e ){
			getLog().error(e.toString());
			return null; 
		}
	}

	@Override
	public long countAll() {
		return super.countAll();
	}


}
